home *** CD-ROM | disk | FTP | other *** search
Text File | 1991-11-01 | 55.5 KB | 1,237 lines |
- Newsgroups: comp.sources.misc
- From: daveg@synaptics.com (David Gillespie)
- Subject: v24i093: gnucalc - GNU Emacs Calculator, v2.00, Part45/56
- Message-ID: <1991Nov1.183815.21088@sparky.imd.sterling.com>
- X-Md4-Signature: c3d46628da92d9d49685f495d4f87a95
- Date: Fri, 1 Nov 1991 18:38:15 GMT
- Approved: kent@sparky.imd.sterling.com
-
- Submitted-by: daveg@synaptics.com (David Gillespie)
- Posting-number: Volume 24, Issue 93
- Archive-name: gnucalc/part45
- Environment: Emacs
- Supersedes: gmcalc: Volume 13, Issue 27-45
-
- ---- Cut Here and unpack ----
- #!/bin/sh
- # do not concatenate these parts, unpack them in order with /bin/sh
- # file calc.texinfo continued
- #
- if test ! -r _shar_seq_.tmp; then
- echo 'Please unpack part 1 first!'
- exit 1
- fi
- (read Scheck
- if test "$Scheck" != 45; then
- echo Please unpack part "$Scheck" next!
- exit 1
- else
- exit 0
- fi
- ) < _shar_seq_.tmp || exit 1
- if test ! -f _shar_wnt_.tmp; then
- echo 'x - still skipping calc.texinfo'
- else
- echo 'x - continuing file calc.texinfo'
- sed 's/^X//' << 'SHAR_EOF' >> 'calc.texinfo' &&
- @end group
- X
- @node Rearranging with Selections, , Operating on Selections, Selecting Subformulas
- @subsection Rearranging Formulas using Selections
- X
- @noindent
- @kindex j R
- @pindex calc-commute-right
- The @kbd{j R} (@code{calc-commute-right}) command moves the selected
- sub-formula to the right in its surrounding formula. Generally the
- selection is one term of a sum or product; the sum or product is
- rearranged according to the commutative laws of algebra.
- X
- As with @kbd{j '} and @kbd{j DEL}, the term under the cursor is used
- if there is no selection in the current formula. All commands described
- in this section share this property. In this example, we place the
- cursor on the @samp{a} and type @kbd{j R}, then repeat.
- X
- @smallexample
- 1: a + b - c 1: b + a - c 1: b - c + a
- @end smallexample
- X
- @noindent
- Note that in the final step above, the @samp{a} is switched with
- the @samp{c} but the signs are adjusted accordingly. When moving
- terms of sums and products, @kbd{j R} will never change the
- mathematical meaning of the formula.
- X
- The selected term may also be an element of a vector or an argument
- of a function. The term is exchanged with the one to its right.
- In this case, the ``meaning'' of the vector or function may of
- course be drastically changed.
- X
- @smallexample
- 1: [a, b, c] 1: [b, a, c] 1: [b, c, a]
- X
- 1: f(a, b, c) 1: f(b, a, c) 1: f(b, c, a)
- @end smallexample
- X
- @kindex j L
- @pindex calc-commute-left
- The @kbd{j L} (@code{calc-commute-left}) command is like @kbd{j R}
- except that it swaps the selected term with the one to its left.
- X
- With numeric prefix arguments, these commands move the selected
- term several steps at a time. It is an error to try to move a
- term left or right past the end of its enclosing formula.
- X
- With numeric prefix arguments of zero, these commands move the
- selected term as far as possible in the given direction, with
- no possibility of signalling an error.
- X
- @kindex j D
- @pindex calc-sel-distribute
- The @kbd{j D} (@code{calc-sel-distribute}) command mixes the selected
- sum or product into the surrounding formula using the distributive
- law. For example, in @samp{a * (b - c)} with the @samp{b - c}
- selected, the result is @samp{a b - a c}. This also distributes
- products or quotients into surrounding powers, and can also do
- transformations like @samp{exp(a + b)} to @samp{exp(a) exp(b)},
- where @samp{a + b} is the selected term, and @samp{ln(a ^ b)}
- to @samp{ln(a) b}, where @samp{a ^ b} is the selected term.
- X
- For multiple-term sums or products, @kbd{j D} takes off one term
- at a time: @samp{a * (b + c - d)} goes to @samp{a * (c - d) + a b}
- with the @samp{c - d} selected so that you can type @kbd{j D}
- repeatedly to expand completely. The @kbd{j D} command allows a
- numeric prefix argument which specifies the maximum number of
- times to expand at once; the default is one time only.
- X
- @vindex DistribRules
- The @kbd{j D} command is implemented using rewrite rules.
- @xref{Selections with Rewrite Rules}. The rules are stored in
- the Calc variable @code{DistribRules}. A convenient way to view
- these rules is to use @kbd{s e} (@code{calc-edit-variable}) which
- displays and edits the stored value of a variable. Press @key{M-# M-#}
- to return from editing mode; be careful not to make any actual changes
- or else you will affect the behavior of future @kbd{j D} commands!
- X
- To extend @kbd{j D} to handle new cases, just edit @code{DistribRules}
- as described above. You can then use the @kbd{s p} command to save
- this variable's value permanently for future Calc sessions.
- X
- @kindex j M
- @pindex calc-sel-merge
- @vindex MergeRules
- The @kbd{j M} (@code{calc-sel-merge}) command is the complement
- of @kbd{j D}; given @samp{a b - a c} with either @samp{a b} or
- @samp{a c} selected, the result is @samp{a * (b - c)}. Once
- again, @kbd{j M} can also merge calls to functions like @code{exp}
- and @code{ln}; examine the variable @code{MergeRules} to see all
- the relevant rules.
- X
- @kindex j C
- @pindex calc-sel-commute
- @vindex CommuteRules
- The @kbd{j C} (@code{calc-sel-commute}) command swaps the arguments
- of the selected sum, product, or equation. It always behaves as
- if @kbd{j b} mode were in effect, i.e., the sum @samp{a + b + c} is
- treated as the nested sums @samp{(a + b) + c} by this command.
- If you put the cursor on the first @samp{+}, the result is
- @samp{(b + a) + c}; if you put the cursor on the second @samp{+}, the
- result is @samp{c + (a + b)} (which the default simplifications
- will rearrange to @samp{(c + a) + b}). The relevant rules are stored
- in the variable @code{CommuteRules}.
- X
- You may need to turn default simplifications off (with the @kbd{m O}
- command) in order to get the full benefit of @kbd{j C}. For example,
- commuting @samp{a - b} produces @samp{-b + a}, but the default
- simplifications will ``simplify'' this right back to @samp{a - b} if
- you don't turn them off. The same is true of some of the other
- manipulations described in this section.
- X
- @kindex j N
- @pindex calc-sel-negate
- @vindex NegateRules
- The @kbd{j N} (@code{calc-sel-negate}) command replaces the selected
- term with the negative of that term, then adjusts the surrounding
- formula in order to preserve the meaning. For example, given
- @samp{exp(a - b)} where @samp{a - b} is selected, the result is
- @samp{1 / exp(b - a)}. By contrast, selecting a term and using the
- regular @kbd{n} (@code{calc-change-sign}) command negates the
- term without adjusting the surroundings, thus changing the meaning
- of the formula as a whole. The rules variable is @code{NegateRules}.
- X
- @kindex j &
- @pindex calc-sel-invert
- @vindex InvertRules
- The @kbd{j &} (@code{calc-sel-invert}) command is similar to @kbd{j N}
- except it takes the reciprocal of the selected term. For example,
- given @samp{a - ln(b)} with @samp{b} selected, the result is
- @samp{a + ln(1/b)}. The rules variable is @code{InvertRules}.
- X
- @kindex j E
- @pindex calc-sel-jump-equals
- @vindex JumpRules
- The @kbd{j E} (@code{calc-sel-jump-equals}) command moves the
- selected term from one side of an equation to the other. Given
- @samp{a + b = c + d} with @samp{c} selected, the result is
- @samp{a + b - c = d}. This command also works if the selected
- term is part of a @samp{*}, @samp{/}, or @samp{^} formula. The
- relevant rules variable is @code{JumpRules}.
- X
- @kindex j I
- @kindex H j I
- @pindex calc-sel-isolate
- The @kbd{j I} (@code{calc-sel-isolate}) command isolates the
- selected term on its side of an equation. It uses the @kbd{a S}
- (@code{calc-solve-for}) command to solve the equation, and the
- Hyperbolic flag affects it in the same way. @xref{Solving Equations}.
- When it applies, @kbd{j I} is often easier to use than @kbd{j E}.
- It understands more rules of algebra, and works for inequalities
- as well as equations.
- X
- @kindex j *
- @kindex j /
- @pindex calc-sel-mult-both-sides
- @pindex calc-sel-div-both-sides
- The @kbd{j *} (@code{calc-sel-mult-both-sides}) command prompts for a
- formula using algebraic entry, then multiplies both sides of the
- selected quotient or equation by that formula. It simplifies each
- side with @kbd{a s} (@code{calc-simplify}) before re-forming the
- quotient or equation. You can suppress this simplification by
- providing any numeric prefix argument. There is also a @kbd{j /}
- (@code{calc-sel-div-both-sides}) which is similar to @kbd{j *} but
- dividing instead of multiplying by the factor you enter.
- X
- As a special feature, if the numerator of the quotient is 1, then
- the denominator is expanded at the top level using the distributive
- law (i.e., using the @kbd{C-u -1 a x} command). Suppose the
- formula on the stack is @samp{1 / (sqrt(a) + 1)}, and you wish
- to eliminate the square root in the denominator by multiplying both
- sides by @samp{sqrt(a) - 1}. Calc's default simplifications would
- change the result @samp{(sqrt(a) - 1) / (sqrt(a) - 1) (sqrt(a) + 1)}
- right back to the original form by cancellation; Calc expands the
- denominator to @samp{sqrt(a) (sqrt(a) - 1) + sqrt(a) - 1} to prevent
- this. (You would now want to use an @kbd{a x} command to expand
- the rest of the way, whereupon the denominator would cancel out to
- the desired form, @samp{a - 1}.) When the numerator is not 1, this
- initial expansion is not necessary because Calc's default
- simplifications will not notice the potential cancellation.
- X
- If the selection is an inequality, @kbd{j *} and @kbd{j /} will
- accept any factor, but will warn unless it can prove the factor
- is either positive or negative. (In the latter case the direction
- of the inequality will be switched appropriately.) @xref{Declarations},
- for ways to inform Calc that a given variable is positive or
- negative. If Calc can't tell for sure what the sign of the factor
- will be, it will assume it is positive and display a warning
- message.
- X
- For selections that are not quotients, equations, or inequalities,
- these commands pull out a multiplicative factor: They divide (or
- multiply) by the entered formula, simplify, then multiply (or divide)
- back by the formula.
- X
- @kindex j +
- @kindex j -
- @pindex calc-sel-add-both-sides
- @pindex calc-sel-sub-both-sides
- The @kbd{j +} (@code{calc-sel-add-both-sides}) and @kbd{j -}
- (@code{calc-sel-sub-both-sides}) commands analogously add to or
- subtract from both sides of an equation or inequality. For other
- types of selections, they extract an additive factor. A numeric
- prefix argument suppresses simplification of the intermediate
- results.
- X
- @kindex j U
- @pindex calc-sel-unpack
- The @kbd{j U} (@code{calc-sel-unpack}) command replaces the
- selected function call with its argument. For example, given
- @samp{a + sin(x^2)} with @samp{sin(x^2)} selected, the result
- is @samp{a + x^2}. (The @samp{x^2} will remain selected; if you
- wanted to change the @code{sin} to @code{cos}, just press @kbd{C}
- now to take the cosine of the selected part.)
- X
- @kindex j v
- @pindex calc-sel-evaluate
- The @kbd{j v} (@code{calc-sel-evaluate}) command performs the
- normal default simplifications on the selected sub-formula.
- These are the simplifications that are normally done automatically
- on all results, but which may have been partially inhibited by
- previous selection-related operations, or turned off altogether
- by the @kbd{m O} command. This command is just an auto-selecting
- version of the @w{@kbd{a v}} command (@pxref{Algebraic Manipulation}).
- X
- With a numeric prefix argument of 2, @kbd{C-u 2 j v} applies
- the @kbd{a s} (@code{calc-simplify}) command to the selected
- sub-formula. With a prefix argument of 3 or more, e.g., @kbd{C-u j v}
- applies the @kbd{a e} (@code{calc-simplify-extended}) command.
- @xref{Simplifying Formulas}. With a negative prefix argument
- it simplifies at the top level only, just as with @kbd{a v}.
- Here the ``top'' level refers to the top level of the selected
- sub-formula.
- X
- @kindex j "
- @pindex calc-sel-expand-formula
- The @kbd{j "} (@code{calc-sel-expand-formula}) command is to @kbd{a "}
- (@pxref{Algebraic Manipulation}) what @kbd{j v} is to @kbd{a v}.
- X
- You can use the @kbd{j r} (@code{calc-rewrite-selection}) command
- to define other algebraic operations on sub-formulas. @xref{Rewrite Rules}.
- X
- @node Algebraic Manipulation, Simplifying Formulas, Selecting Subformulas, Algebra
- @section Algebraic Manipulation
- X
- @noindent
- The commands in this section perform general-purpose algebraic
- manipulations. They work on the whole formula at the top of the
- stack (unless, of course, you have made a selection in that
- formula).
- X
- Many algebra commands prompt for a variable name or formula. If you
- answer the prompt with a blank line, the variable or formula is taken
- from top-of-stack, and the normal argument for the command is taken
- from the second-to-top stack level.
- X
- @kindex a v
- @pindex calc-alg-evaluate
- The @kbd{a v} (@code{calc-alg-evaluate}) command performs the normal
- default simplifications on a formula; for example, @samp{a - -b} is
- changed to @samp{a + b}. These simplifications are normally done
- automatically on all Calc results, so this command is useful only if
- you have turned default simplifications off with an @kbd{m O}
- command. @xref{Simplification Modes}.
- X
- It is often more convenient to type @kbd{=}, which is like @kbd{a v}
- but which also substitutes stored values for variables in the formula.
- Use @kbd{a v} if you want the variables to ignore their stored values.
- X
- If you give a numeric prefix argument of 2 to @kbd{a v}, it simplifies
- as if in algebraic simplification mode; this is equivalent to typing
- @kbd{a s}; @pxref{Simplifying Formulas}. If you give a numeric prefix
- of 3 or more, it uses extended simplification mode (@kbd{a e}).
- X
- If you give a negative prefix argument @i{-1}, @i{-2}, or @i{-3},
- it simplifies in the corresponding mode but only works on the top-level
- function call of the formula. For example, @samp{(2 + 3) * (2 + 3)} will
- simplify to @samp{(2 + 3)^2}, without simplifying the sub-formulas
- @samp{2 + 3}. As another example, typing @kbd{V R +} to sum the vector
- @samp{[1, 2, 3, 4]} produces the formula @samp{reduce(add, [1, 2, 3, 4])}
- in no-simplify mode. Using @kbd{a v} will evaluate this all the way to
- 10; using @kbd{C-u - a v} will evaluate it only to @samp{1 + 2 + 3 + 4}.
- (@xref{Reducing and Mapping}.)
- X
- @tindex evalv
- @tindex evalvn
- Two related forms of evaluation are the @kbd{=} command, which is
- like @kbd{a v} but first substitutes all variables in the formula
- with their stored values, if any, and the @kbd{N} command, which
- is like @kbd{=} but temporarily disables symbolic (@kbd{m s}) mode
- during the evaluation. The algebraic functions @code{evalv} and
- @code{evalvn}, respectively, also accomplish this. (These commands
- interpret their prefix arguments differently than @kbd{a v}; @kbd{=}
- treats the prefix as the number of stack elements to evaluate at
- once, and @kbd{N} treats it as a temporary different working
- precision.)
- X
- The @code{evalvn} function can take an alternate working precision
- as an optional second argument. This argument can be either an
- integer, to set the precision absolutely, or an vector containing
- a single integer, to adjust the precision relative to the current
- precision. Note that @code{evalvn} with a larger than current
- precision will do the calculation at this higher precision, but the
- result will as usual be rounded back down to the current precision
- afterward. For example, @samp{evalvn(pi - 3.1415)} at a precision
- of 12 will return @samp{9.265359e-5}; @samp{evalvn(pi - 3.1415, 30)}
- will return @samp{9.26535897932e-5} (computing a 25-digit result which
- is then rounded down to 12); and @samp{evalvn(pi - 3.1415, [-2])}
- will return @samp{9.2654e-5}.
- X
- @kindex a "
- @pindex calc-expand-formula
- The @kbd{a "} (@code{calc-expand-formula}) command expands functions
- into their defining formulas wherever possible. For example,
- @samp{deg(x^2)} is changed to @samp{180 x^2 / pi}. Most functions,
- like @code{sin} and @code{gcd}, are not defined by simple formulas
- and so are unaffected by this command. One important class of
- functions which @emph{can} be expanded is the user-defined functions
- created by the @kbd{Z F} command. @xref{Algebraic Definitions}.
- Other functions which @kbd{a "} can expand include the probability
- distribution functions, most of the financial functions, and the
- hyperbolic and inverse hyperbolic functions. A numeric prefix argument
- affects @kbd{a "} in the same way as it does @kbd{a v}: A positive
- argument expands all functions in the formula and then simplifies in
- various ways; a negative argument expands and simplifies only the
- top-level function call.
- X
- @kindex a M
- @pindex calc-map-equation
- @tindex mapeq
- The @kbd{a M} (@code{calc-map-equation}) [@code{mapeq}] command applies
- a given function or operator to one or more equations. It is analogous
- to @kbd{V M}, which operates on vectors instead of equations.
- @pxref{Reducing and Mapping}. For example, @kbd{a M S} changes
- @samp{x = y+1} to @samp{sin(x) = sin(y+1)}, and @kbd{a M +} with
- @samp{x = y+1} and @cite{6} on the stack produces @samp{x+6 = y+7}.
- With two equations on the stack, @kbd{a M +} would add the lefthand
- sides together and the righthand sides together to get the two sides
- of a new equation.
- X
- Mapping also works on inequalities. Mapping two similar inequalities
- produces another inequality of the same type. Mapping an inequality
- with an equation produces an inequality of the same type. Mapping a
- @samp{<=} with a @samp{<} or @samp{!=} (not-equal) produces a @samp{<}.
- If inequalities with opposite direction (e.g., @samp{<} and @samp{>})
- are mapped, the direction of the second inequality is reversed.
- X
- Using @kbd{a M *}, @kbd{a M /}, @kbd{a M n}, or @kbd{a M &} to negate
- or invert an inequality will reverse the direction of the inequality.
- Other adjustments to inequalities are @emph{not} done automatically;
- @kbd{a M S} will change @samp{x < y} to @samp{sin(x) < sin(y)} even
- though this is not true for all values of the variables.
- X
- @kindex H a M
- @tindex mapeqp
- With the Hyperbolic flag, @kbd{H a M} [@code{mapeqp}] does a plain
- mapping operation without reversing the direction of any inequalities.
- Thus, @kbd{H a M &} would change @kbd{x > 2} to @kbd{1/x > 0.5}.
- (This change is mathematically incorrect, but perhaps you were
- fixing an inequality which was already incorrect.)
- X
- @kindex I a M
- @tindex mapeqr
- With the Inverse flag, @kbd{I a M} [@code{mapeqr}] always reverses
- the direction of the inequality. You might use @kbd{I a M C} to
- change @samp{x < y} to @samp{cos(x) > cos(y)} if you knew you were
- working with small positive angles.
- X
- @kindex a b
- @pindex calc-substitute
- @tindex subst
- The @kbd{a b} (@code{calc-substitute}) [@code{subst}] command substitutes
- all occurrences
- of some variable or sub-expression of an expression with a new
- sub-expression. For example, substituting @samp{sin(x)} with @samp{cos(y)}
- in @samp{2 sin(x)^2 + x sin(x) + sin(2 x)} produces
- @samp{2 cos(y)^2 + x cos(y) + sin(2 x)}.
- Note that this is a purely structural substitution; the lone @code{x} and the
- @samp{sin(2 x)} stayed the same because they did not look like
- @samp{sin(x)}. @xref{Rewrite Rules}, for a more general method for
- doing substitutions.@refill
- X
- The @code{calc-substitute} command normally prompts for two formulas,
- the old one and the new one. If you enter a blank line for the first
- prompt, all three arguments are taken from the stack (new, then old,
- then target expression). If you type an old formula but then enter a
- blank line for the new one, the new formula is taken from top-of-stack
- and the target from second-to-top. If you answer both prompts, the
- target is taken from top-of-stack as usual.
- X
- Note that @code{calc-substitute} has no understanding of commutativity
- or associativity. The pattern @samp{x+y} will not match the formula
- @samp{y+x}. Also, @samp{y+z} will not match inside the formula @samp{x+y+z}
- because the @samp{+} operator is left-associative, so the ``deep
- structure'' of that formula is @samp{(x+y) + z}. Use @kbd{d U}
- (@code{calc-unformatted-language}) mode to see the true structure of
- a formula. The rewrite rule mechanism, discussed later, does not have
- these limitations.
- X
- As an algebraic function, @code{subst} takes three arguments:
- Target expression, old, new. Note that @code{subst} is always
- evaluated immediately, even if its arguments are variables, so if
- you wish to put a call to @code{subst} onto the stack you must
- turn the default simplifications off first (with @kbd{m O}).
- X
- @node Simplifying Formulas, Polynomials, Algebraic Manipulation, Algebra
- @section Simplifying Formulas
- X
- @noindent
- @kindex a s
- @pindex calc-simplify
- @tindex simplify
- The @kbd{a s} (@code{calc-simplify}) [@code{simplify}] command applies
- various algebraic rules to simplify a formula. This includes rules which
- are not part of the default simplifications because they may be too slow
- to apply all the time, or may not be desirable all of the time. For
- example, non-adjacent terms of sums are combined, as in @samp{a + b + 2 a}
- to @samp{b + 3 a}, and some formulas like @samp{sin(arcsin(x))} are
- simplified to @samp{x}.
- X
- The sections below describe all the various kinds of algebraic
- simplifications Calc provides in full detail. None of Calc's
- simplification commands are designed to pull rabbits out of hats;
- they simply apply certain specific rules to put formulas into
- less redundant or more pleasing forms. Serious algebra in Calc
- must be done manually, usually with a combination of selections
- and rewrite rules. @xref{Rearranging with Selections}.
- @xref{Rewrite Rules}.
- X
- @xref{Simplification Modes}, for commands to control what level of
- simplification occurs automatically. Normally only the ``default
- simplifications'' occur.
- X
- @menu
- * Default Simplifications::
- * Algebraic Simplifications::
- * Unsafe Simplifications::
- * Simplification of Units::
- @end menu
- X
- @node Default Simplifications, Algebraic Simplifications, Simplifying Formulas, Simplifying Formulas
- @subsection Default Simplifications
- X
- @noindent
- @cindex Default Simplifications
- This section describes the ``default simplifications,'' those which are
- normally applied to all results. For example, if you enter the variable
- @cite{x} on the stack twice and push @kbd{+}, Calc's default
- simplifications automatically change @cite{x + x} to @cite{2 x}.
- X
- The @kbd{m O} command turns off the default simplifications, so that
- @cite{x + x} will remain in this form unless you give an explicit
- ``simplify'' command like @kbd{=} or @kbd{a v}. @xref{Algebraic
- Manipulation}. The @kbd{m D} command turns the default simplifications
- back on.
- X
- The most basic default simplification is the evaluation of functions.
- For example, @cite{2 + 3} is evaluated to @cite{5}, and @cite{@t{sqrt}(9)}
- is evaluated to @cite{3}. Evaluation does not occur if the arguments
- to a function are somehow of the wrong type (@cite{@t{tan}([2,3,4])},
- range (@cite{@t{tan}(90)}), or number (@cite{@t{tan}(3,5)}), or if the
- function name is not recognized (@cite{@t{f}(5)}), or if ``symbolic''
- mode (@pxref{Symbolic Mode}) prevents evaluation (@cite{@t{sqrt}(2)}).
- X
- Calc simplifies (evaluates) the arguments to a function before it
- simplifies the function itself. Thus @cite{@t{sqrt}(5+4)} is
- simplified to @cite{@t{sqrt}(9)} before the @code{sqrt} function
- itself is examined. There are very few exceptions to this rule:
- @code{quote}, @code{lambda}, and @code{condition} (the @code{::}
- operator) do not simplify their arguments, @code{if} (the @code{? :}
- operator) does not evaluate all of its arguments, and @code{evalto}
- does not evaluate its lefthand argument.
- X
- Most commands apply the default simplifications to all arguments they
- take from the stack, perform a particular operation, then simplify
- the result before pushing it back on the stack. In the common special
- case of regular arithmetic commands like @kbd{+} and @kbd{Q} [@code{sqrt}],
- the arguments are simply popped from the stack and collected into a
- suitable function call, which is then simplified (the arguments being
- simplified first as part of the process, as described above).
- X
- The default simplifications are too numerous to describe completely
- here, but this section will describe the ones that apply to the
- major arithmetic operators. This list will be rather technical in
- nature, and will probably be interesting to you only if you are
- a serious user of Calc's algebra facilities.
- X
- @tex
- \bigskip
- @end tex
- X
- As well as the simplifications described here, if you have stored
- any rewrite rules in the variable @code{EvalRules} then these rules
- will also be applied before the built-in default simplifications.
- @xref{Automatic Rewrites}, for details.
- X
- @tex
- \bigskip
- @end tex
- X
- And now, on with the default simplifications:
- X
- Arithmetic operators like @kbd{+} and @kbd{*} always take two
- arguments in Calc's internal form. Sums and products of three or
- more terms are arranged by the associative law of algebra into
- a left-associative form for sums, @cite{((a + b) + c) + d}, and
- a right-associative form for products, @cite{a * (b * (c * d))}.
- Formulas like @cite{(a + b) + (c + d)} are rearranged to
- left-associative form, though this rarely matters since Calc's
- algebra commands are designed to hide the inner structure of
- sums and products as much as possible. Sums and products in
- their proper associative form will be written without parentheses
- in the examples below.
- X
- Sums and products are @emph{not} rearranged according to the
- commutative law (@cite{a + b} to @cite{b + a}) except in a few
- special cases described below. Some algebra programs always
- rearrange terms into a canonical order, which enables them to
- see that @cite{a b + b a} can be simplified to @cite{2 a b}.
- Calc assumes you have put the terms into the order you want
- and generally leaves that order alone, with the consequence
- that formulas like the above will only be simplified if you
- explicitly give the @kbd{a s} command. @xref{Algebraic
- Simplifications}.
- X
- Differences @cite{a - b} are treated like sums @cite{a + (-b)}
- for purposes of simplification; one of the default simplifications
- is to rewrite @cite{a + (-b)} or @cite{(-b) + a}, where @cite{-b}
- represents a ``negative-looking'' term, into @cite{a - b} form.
- ``Negative-looking'' means negative numbers, negated formulas like
- @cite{-x}, and products or quotients in which either term is
- negative-looking.
- X
- Other simplifications involving negation are @cite{-(-x)} to @cite{x};
- @cite{-(a b)} or @cite{-(a/b)} where either @cite{a} or @cite{b} is
- negative-looking, simplified by negating that term, or else where
- @cite{a} or @cite{b} is any number, by negating that number;
- @cite{-(a + b)} to @cite{-a - b}, and @cite{-(b - a)} to @cite{a - b}.
- (This, and rewriting @cite{(-b) + a} to @cite{a - b}, are the only
- cases where the order of terms in a sum is changed by the default
- simplifications.)
- X
- The distributive law is used to simplify sums in some cases:
- @cite{a x + b x} to @cite{(a + b) x}, where @cite{a} represents
- a number or an implicit 1 or @i{-1} (as in @cite{x} or @cite{-x})
- and similarly for @cite{b}. Use the @kbd{a c} or @kbd{j M}
- commands to merge sums with non-numeric coefficients using the
- distributive law.
- X
- The distributive law is only used for sums of two terms, or
- for adjacent terms in a larger sum. Thus @cite{a + b + b + c}
- is simplified to @cite{a + 2 b + c}, but @cite{a + b + c + b}
- is not simplified. The reason is that comparing all terms of a
- sum with one another would require time proportional to the
- square of the number of terms; Calc relegates potentially slow
- operations like this to commands that have to be invoked
- explicitly, like @kbd{a s}.
- X
- Finally, @cite{a + 0} and @cite{0 + a} are simplified to @cite{a}.
- A consequence of the above rules is that @cite{0 - a} is simplified
- to @cite{-a}.
- X
- @tex
- \bigskip
- @end tex
- X
- The products @cite{1 a} and @cite{a 1} are simplified to @cite{a};
- @cite{(-1) a} and @cite{a (-1)} are simplified to @cite{-a};
- @cite{0 a} and @cite{a 0} are simplified to @cite{0}, except that
- in matrix mode where @cite{a} is not provably scalar the result
- is the generic zero matrix @samp{idn(0)}, or that if @cite{a} is
- infinite the result is @samp{nan}.
- X
- Also, @cite{(-a) b} and @cite{a (-b)} are simplified to @cite{-(a b)},
- where this occurs for negated formulas but not for regular negative
- numbers.
- X
- Products are commuted only to move numbers to the front:
- @cite{a b 2} is commuted to @cite{2 a b}.
- X
- The product @cite{a (b + c)} is distributed over the sum only if
- @cite{a} and at least one of @cite{b} and @cite{c} are numbers:
- @cite{2 (x + 3)} goes to @cite{2 x + 6}. The formula
- @cite{(-a) (b - c)}, where @cite{-a} is a negative number, is
- rewritten to @cite{a (c - b)}.
- X
- The distributive law of products and powers is used for adjacent
- terms of the product: @cite{x^a x^b} goes to @c{$x^{a+b}$}
- @cite{x^(a+b)}
- where @cite{a} is a number, or an implicit 1 (as in @cite{x}),
- or the implicit one-half of @cite{@t{sqrt}(x)}, and similarly for
- @cite{b}. The result is written using @samp{sqrt} or @samp{1/sqrt}
- if the sum of the powers is @cite{1/2} or @cite{-1/2}, respectively.
- If the sum of the powers is zero, the product is simplified to
- @cite{1} or to @samp{idn(1)} if matrix mode is enabled.
- X
- The product of a negative power times anything but another negative
- power is changed to use division: @c{$x^{-2} y$}
- @cite{x^(-2) y} goes to @cite{y / x^2} unless matrix mode is
- in effect and neither @cite{x} nor @cite{y} are scalar (in which
- case it is considered unsafe to rearrange the order of the terms).
- X
- Finally, @cite{a (b/c)} is rewritten to @cite{(a b)/c}, and also
- @cite{(a/b) c} is changed to @cite{(a c)/b} unless in matrix mode.
- X
- @tex
- \bigskip
- @end tex
- X
- Simplifications for quotients are analogous to those for products.
- The quotient @cite{0 / x} is simplified to @cite{0}, with the same
- exceptions that were noted for @cite{0 x}. Likewise, @cite{x / 1}
- and @cite{x / (-1)} are simplified to @cite{x} and @cite{-x},
- respectively.
- X
- The quotient @cite{x / 0} is left unsimplified or changed to an
- infinite quantity, as directed by the current infinite mode.
- @xref{Infinite Mode}.
- X
- The expression @c{$a / b^{-c}$}
- @cite{a / b^(-c)} is changed to @cite{a b^c},
- where @cite{-c} is any negative-looking power. Also, @cite{1 / b^c}
- is changed to @c{$b^{-c}$}
- @cite{b^(-c)} for any power @cite{c}.
- X
- Also, @cite{(-a) / b} and @cite{a / (-b)} go to @cite{-(a/b)};
- @cite{(a/b) / c} goes to @cite{a / (b c)}; and @cite{a / (b/c)}
- goes to @cite{(a c) / b} unless matrix mode prevents this
- rearrangement. Similarly, @cite{a / (b:c)} is simplified to
- @cite{(c:b) a} for any fraction @cite{b:c}.
- X
- The distributive law is applied to @cite{(a + b) / c} only if
- @cite{c} and at least one of @cite{a} and @cite{b} are numbers.
- Quotients of powers and square roots are distributed just as
- described for multiplication.
- X
- Quotients of products cancel only in the leading terms of the
- numerator and denominator. In other words, @cite{a x b / a y b}
- is cancelled to @cite{x b / y b} but not to @cite{x / y}. Once
- again this is because full cancellation can be slow; use @kbd{a s}
- to cancel all terms of the quotient.
- X
- Quotients of negative-looking values are simplified according
- to @cite{(-a) / (-b)} to @cite{a / b}, @cite{(-a) / (b - c)}
- to @cite{a / (c - b)}, and @cite{(a - b) / (-c)} to @cite{(b - a) / c}.
- X
- @tex
- \bigskip
- @end tex
- X
- The formula @cite{x^0} is simplified to @cite{1}, or to @samp{idn(1)}
- in matrix mode. The formula @cite{0^x} is simplified to @cite{0}
- unless @cite{x} is a negative number or complex number, in which
- case the result is an infinity or an unsimplified formula according
- to the current infinite mode. Note that @cite{0^0} is an
- indeterminate form, as evidenced by the fact that the simplifications
- for @cite{x^0} and @cite{0^x} conflict when @cite{x=0}.
- X
- Powers of products or quotients @cite{(a b)^c}, @cite{(a/b)^c}
- are distributed to @cite{a^c b^c}, @cite{a^c / b^c} only if @cite{c}
- is an integer, or if either @cite{a} or @cite{b} are nonnegative
- real numbers. Powers of powers @cite{(a^b)^c} are simplified to
- @c{$a^{b c}$}
- @cite{a^(b c)} only when @cite{c} is an integer and @cite{b c} also
- evaluates to an integer. Without these restrictions these simplifications
- would not be safe because of problems with principal values.
- @xref{Declarations}, for ways to inform Calc that your variables
- satisfy these requirements.
- X
- As a special case of this rule, @cite{@t{sqrt}(x)^n} is simplified to
- @c{$x^{n/2}$}
- @cite{x^(n/2)} only for even integers @cite{n}.
- X
- If @cite{a} is known to be real, @cite{b} is an even integer, and
- @cite{c} is a half- or quarter-integer, then @cite{(a^b)^c} is
- simplified to @c{$@t{abs}(a^{b c})$}
- @cite{@t{abs}(a^(b c))}.
- X
- Also, @cite{(-a)^b} is simplified to @cite{a^b} if @cite{b} is an
- even integer, or to @cite{-(a^b)} if @cite{b} is an odd integer,
- for any negative-looking expression @cite{-a}.
- X
- Square roots @cite{@t{sqrt}(x)} generally act like one-half powers
- @c{$x^{1:2}$}
- @cite{x^1:2} for the purposes of the above-listed simplifications.
- X
- Also, note that @c{$1 / x^{1:2}$}
- @cite{1 / x^1:2} is changed to @c{$x^{-1:2}$}
- @cite{x^(-1:2)},
- but @cite{1 / @t{sqrt}(x)} is left alone.
- X
- @tex
- \bigskip
- @end tex
- X
- Generic identity matrices (@pxref{Matrix Mode}) are simplified by the
- following rules: @cite{@t{idn}(a) + b} to @cite{a + b} if @cite{b}
- is provably scalar, or expanded out if @cite{b} is a matrix;
- @cite{@t{idn}(a) + @t{idn}(b)} to @cite{@t{idn}(a + b)};
- @cite{-@t{idn}(a)} to @cite{@t{idn}(-a)}; @cite{a @t{idn}(b)} to
- @cite{@t{idn}(a b)} if @cite{a} is provably scalar, or to @cite{a b}
- if @cite{a} is provably non-scalar; @cite{@t{idn}(a) @t{idn}(b)}
- to @cite{@t{idn}(a b)}; analogous simplifications for quotients
- involving @code{idn}; and @cite{@t{idn}(a)^n} to @cite{@t{idn}(a^n)}
- where @cite{n} is an integer.
- X
- @tex
- \bigskip
- @end tex
- X
- The @code{float} function and other integer truncation functions
- vanish if the argument is provably integer-valued, so that
- @cite{@t{floor}(@t{round}(x))} simplifies to @cite{@t{round}(x)}.
- Also, combinations of @code{float}, @code{floor} and its friends,
- and @code{ffloor} and its friends, are simplified in appropriate
- ways. @xref{Integer Truncation}.
- X
- The expression @cite{@t{abs}(-x)} changes to @cite{@t{abs}(x)}.
- The expression @cite{@t{abs}(@t{abs}(x))} changes to @cite{@t{abs}(x)};
- in fact, @cite{@t{abs}(x)} changes to @cite{x} or @cite{-x} if @cite{x}
- is provably nonnegative or nonpositive (@pxref{Declarations}).
- X
- While most functions do not recognize the variable @code{i} as an
- imaginary number, the @code{arg} function does handle the two cases
- @cite{@t{arg}(@t{i})} and @cite{@t{arg}(-@t{i})} just for convenience.
- X
- The expression @cite{@t{conj}(@t{conj}(x))} simplifies to @cite{x}.
- Various other expressions involving @code{conj}, @code{re}, and
- @code{im} are simplified, especially if some of the argments are
- provably real or involve the constant @code{i}. For example,
- @cite{@t{conj}(a + b i)} is changed to @cite{@t{conj}(a) - @t{conj}(b) i},
- or to @cite{a - b i} if @cite{a} and @cite{b} are known to be real.
- X
- Functions like @code{sin} and @code{arctan} generally don't have
- any default simplifications beyond simply evaluating the functions
- for suitable numeric arguments and infinity. The @kbd{a s} command
- described in the next section does provide some simplifications for
- these functions, though.
- X
- One important simplification that does occur is that @cite{@t{ln}(@t{e})}
- is simplified to 1, and @cite{@t{ln}(@t{e}^x)} is simplified to @cite{x}
- for any @cite{x}. This occurs even if you have stored a different
- value in the Calc variable @samp{e}; but this would be a bad idea
- in any case if you were also using natural logarithms!
- X
- Among the logical functions, @t{!}@i{(a} @t{<=} @i{b)} changes to
- @cite{a > b} and so on. Equations and inequalities where both sides
- are either negative-looking or zero are simplified by negating both sides
- and reversing the inequality. While it might seem reasonable to simplify
- @cite{@t{!!}x} to @cite{x}, this would not be valid in general because
- @code{!!2} is 1, not 2.
- X
- Most other Calc functions have few if any default simplifications
- defined, aside of course from evaluation when the arguments are
- suitable numbers.
- X
- @node Algebraic Simplifications, Unsafe Simplifications, Default Simplifications, Simplifying Formulas
- @subsection Algebraic Simplifications
- X
- @noindent
- @cindex Algebraic Simplifications
- The @kbd{a s} command makes simplifications that may be too slow to
- do all the time, or that may not be desirable all of the time.
- If you find these simplifications are worthwhile, you can type
- @kbd{m A} to have Calc apply them all the time.
- X
- This section describes all simplifications that are performed by
- the @kbd{a s} command. Note that these occur in addition to the
- default simplifications; even if the default simplifications have
- been turned off by an @kbd{m O} command, @kbd{a s} will turn them
- back on temporarily while it simplifies the formula.
- X
- There is a variable, @code{AlgSimpRules}, in which you can put rewrites
- to be applied by @kbd{a s}. Its use is analogous to @code{EvalRules},
- but without the special cases. Basically, the simplifier does
- @samp{a r AlgSimpRules} with an infinite repeat count on the whole
- expression being simplified, then it traverses the expression applying
- the built-in rules described below. If the result is different from
- the original expression, the process repeats with the default
- simplifications (including @code{EvalRules}), then @code{AlgSimpRules},
- then the built-in simplifications, and so on.
- X
- @tex
- \bigskip
- @end tex
- X
- Sums are simplified in two ways. Constant terms are commuted to the
- end of the sum, so that @cite{a + 2 + b} changes to @cite{a + b + 2}.
- The only exception is that a constant will not be commuted away
- from the first position of a difference, i.e., @cite{2 - x} is not
- commuted to @cite{-x + 2}.
- X
- Also, terms of sums are combined by the distributive law, as in
- @cite{x + y + 2 x} to @cite{y + 3 x}. This always occurs for
- adjacent terms, but @kbd{a s} compares all pairs of terms including
- non-adjacent ones.
- X
- @tex
- \bigskip
- @end tex
- X
- Products are sorted into a canonical order using the commutative
- law. For example, @cite{b c a} is commuted to @cite{a b c}.
- This allows easier comparison of products; for example, the default
- simplifications will not change @cite{x y + y x} to @cite{2 x y},
- but @kbd{a s} will; it first rewrites the sum to @cite{x y + x y},
- and then the default simplifications are able to recognize a sum
- of identical terms.
- X
- The canonical ordering used to sort terms of products has the
- property that real-valued numbers, interval forms and infinities
- come first, and are sorted into increasing order. The @kbd{V S}
- command uses the same ordering when sorting a vector.
- X
- Sorting of terms of products is inhibited when matrix mode is
- turned on; in this case, Calc will never exchange the order of
- two terms unless it knows at least one of the terms is a scalar.
- X
- Products of powers are distributed by comparing all pairs of
- terms, using the same method that the default simplifications
- use for adjacent terms of products.
- X
- Even though sums are not sorted, the commutative law is still
- taken into account when terms of a product are being compared.
- Thus @cite{(x + y) (y + x)} will be simplified to @cite{(x + y)^2}.
- A subtle point is that @cite{(x - y) (y - x)} will @emph{not}
- be simplified to @cite{-(x - y)^2}; Calc does not notice that
- one term can be written as a constant (@i{-1}) times the other.
- X
- A fraction times any expression, @cite{(a:b) x} is changed to
- a quotient involving integers: @cite{a x / b}. This is not
- done for floating-point numbers like @cite{0.5}, however. This
- is one reason why you may find it convenient to turn Fraction mode
- on while doing algebra; @pxref{Fraction Mode}.
- X
- @tex
- \bigskip
- @end tex
- X
- Quotients are simplified by comparing all terms in the numerator
- with all terms in the denominator for possible cancellation using
- the distributive law. For example, @cite{a x^2 b / c x^3 d} will
- cancel @cite{x^2} from both sides to get @cite{a b / c x d}.
- (The terms in the denominator will then be rearranged to @cite{c d x}
- as described above.) If there is any common integer or fractional
- factor in the numerator and denominator, it is cancelled out;
- for example, @cite{(4 x + 6) / 8 x} simplifies to @cite{(2 x + 3) / 4 x}.
- X
- Non-constant common factors are not found even by @kbd{a s}. To
- cancel the factor @cite{a} in @cite{(a x + a) / a^2} you could first
- use @kbd{j M} on the product @cite{a x} to Merge the numerator to
- @cite{a (1+x)}, which can then be simplified successfully.
- X
- @tex
- \bigskip
- @end tex
- X
- Integer powers of the variable @code{i} are simplified according
- to the identity @cite{i^2 = -1}. If you store a new value other
- than the complex number @cite{(0,1)} in @code{i}, this simplification
- will no longer occur. This is done by @kbd{a s} instead of by default
- in case someone (unwisely) uses the name @code{i} for a variable
- unrelated to complex numbers; it would be unfortunate if Calc
- quietly and automatically changed this formula for reasons the
- user might not have been thinking of.
- X
- Square roots of integer or rational arguments are simplified in
- several ways. (Note that these will be left unevaluated only in
- Symbolic mode.) First, square integer or rational factors are
- pulled out so that @cite{@t{sqrt}(8)} is rewritten as
- @cite{2 @t{sqrt}(2)}. Conceptually speaking this implies factoring
- the argument into primes and moving pairs of primes out of the
- square root, but for reasons of efficiency Calc only looks for
- primes up to 29.
- X
- Square roots in the denominator of a quotient are moved to the
- numerator: @cite{1 / @t{sqrt}(3)} changes to @cite{@t{sqrt}(3) / 3}.
- The same effect occurs for the square root of a fraction:
- @cite{@t{sqrt}(2:3)} changes to @cite{@t{sqrt}(6) / 3}.
- X
- @tex
- \bigskip
- @end tex
- X
- The @code{%} (modulo) operator is simplified in several ways
- when the modulus @cite{M} is a positive real number. First, if
- the argument is of the form @cite{x + n} for some real number
- @cite{n}, then @cite{n} is itself reduced modulo @cite{M}. For
- example, @samp{(x - 23) % 10} is simplified to @samp{(x + 7) % 10}.
- X
- If the argument is multiplied by a constant, and this constant
- has a common integer divisor with the modulus, then this factor is
- cancelled out. For example, @samp{12 x % 15} is changed to
- @samp{3 (4 x % 5)} by factoring out 3. Also, @samp{(12 x + 1) % 15}
- is changed to @samp{3 ((4 x + 1:3) % 5)}. While these forms may
- not seem ``simpler,'' they allow Calc to discover useful information
- about modulo forms in the presence of declarations.
- X
- If the modulus is 1, then Calc can use @code{int} declarations to
- evaluate the expression. For example, the idiom @samp{x % 2} is
- often used to check whether a number is odd or even. As described
- above, @samp{2 n % 2} and @samp{(2 n + 1) % 2} are simplified to
- @samp{2 (n % 1)} and @samp{2 ((n + 1:2) % 1)}, respectively; Calc
- can simplify these to 0 and 1 (respectively) if @code{n} has been
- declared to be an integer.
- X
- @tex
- \bigskip
- @end tex
- X
- Trigonometric functions are simplified in several ways. First,
- @cite{@t{sin}(@t{arcsin}(x))} is simplified to @cite{x}, and
- similarly for @code{cos} and @code{tan}. If the argument to
- @code{sin} is negative-looking, it is simplified to @cite{-@t{sin}(x)},
- and similarly for @code{cos} and @code{tan}. Finally, certain
- special values of the argument are recognized;
- @pxref{Trigonometric and Hyperbolic Functions}.
- X
- Trigonometric functions of inverses of different trigonometric
- functions can also be simplified, as in @cite{@t{sin}(@t{arccos}(x))}
- to @cite{@t{sqrt}(1 - x^2)}.
- X
- Hyperbolic functions of their inverses and of negative-looking
- arguments are also handled, as are exponentials of inverse
- hyperbolic functions.
- X
- No simplifications for inverse trigonometric and hyperbolic
- functions are known, except for negative arguments of @code{arcsin},
- @code{arctan}, @code{arcsinh}, and @code{arctanh}. Note that
- @cite{@t{arcsin}(@t{sin}(x))} can @emph{not} safely change to
- @cite{x}, since this only correct within an integer multiple
- of @c{$2 \pi$}
- @cite{2 pi} radians or 360 degrees. However,
- @cite{@t{arcsinh}(@t{sinh}(x))} is simplified to @cite{x} if
- @cite{x} is known to be real.
- X
- Several simplifications that apply to logarithms and exponentials
- are that @cite{@t{exp}(@t{ln}(x))}, @c{$@t{e}^{\ln(x)}$}
- @cite{e^@t{ln}(x)}, and
- @c{$10^{{\rm log10}(x)}$}
- @cite{10^@t{log10}(x)} all reduce to @cite{x}.
- Also, @cite{@t{ln}(@t{exp}(x))}, etc., can reduce to @cite{x} if
- @cite{x} is provably real. The form @cite{@t{exp}(x)^y} is simplified
- to @cite{@t{exp}(x y)}. If @cite{x} is a suitable multiple of @c{$\pi i$}
- @cite{pi i}
- (as described above for the trigonometric functions), then @cite{@t{exp}(x)}
- or @cite{e^x} will be expanded. Finally, @cite{@t{ln}(x)} is simplified
- to a form involving @code{pi} and @code{i} where @cite{x} is provably
- negative, positive imaginary, or negative imaginary.
- X
- @tex
- \bigskip
- @end tex
- X
- Equations and inequalities are simplified by cancelling factors
- of products, quotients, or sums on both sides. Inequalities
- change sign if a negative multiplicative factor is cancelled.
- Non-constant multiplicative factors as in @cite{a b = a c} are
- cancelled from equations only if they are provably nonzero (generally
- because they were declared so; @pxref{Declarations}). Factors
- are cancelled from inequalities only if they are nonzero and their
- sign is known.
- X
- Simplification also replaces an equation or inequality with
- 1 or 0 (``true'' or ``false'') if it can through the use of
- declarations. If @cite{x} is declared to be an integer greater
- than 5, then @cite{x < 3}, @cite{x = 3}, and @cite{x = 7.5} are
- all simplified to 0, but @cite{x > 3} is simplified to 1.
- By a similar analysis, @cite{abs(x) >= 0} is simplified to 1,
- as is @cite{x^2 >= 0} if @cite{x} is known to be real.
- X
- @node Unsafe Simplifications, Simplification of Units, Algebraic Simplifications, Simplifying Formulas
- @subsection ``Unsafe'' Simplifications
- X
- @noindent
- @cindex Unsafe Simplifications
- @cindex Extended Simplification
- @kindex a e
- @pindex calc-simplify-extended
- @tindex esimplify
- The @kbd{a e} (@code{calc-simplify-extended}) [@code{esimplify}] command
- is like @kbd{a s}
- except that it applies some additional simplifications which are not
- ``safe'' in all cases. Use this only if you know the values in your
- formula lie in the restricted ranges for which these simplifications
- are valid. The symbolic integrator uses @code{calc-simplify-extended};
- one effect of this is that the integrator's results must be used with
- caution. Where an integral table will often attach conditions like
- ``for positive @cite{a} only,'' Calc (like most other symbolic
- integration programs) will simply produce an unqualified result.@refill
- X
- Because @kbd{a e}'s simplifications are unsafe, it is sometimes better
- to type @kbd{C-u - 3 a v}, which does extended simplification only
- on the top level of the formula without affecting the sub-formulas.
- In fact, @kbd{C-u - 3 j v} allows you to target extended simplification
- to any specific part of a formula.
- X
- The variable @code{ExtSimpRules} contains rewrites to be applied by
- the @kbd{a e} command. These are applied in addition to
- @code{EvalRules} and @code{AlgSimpRules}. (The @kbd{a r AlgSimpRules}
- step described above is simply followed by an @kbd{a r ExtSimpRules} step.)
- X
- Following is a complete list of ``unsafe'' simplifications performed
- by @kbd{a e}.
- X
- @tex
- \bigskip
- @end tex
- X
- Inverse trigonometric or hyperbolic functions, called with their
- corresponding non-inverse functions as arguments, are simplified
- by @kbd{a e}. For example, @cite{@t{arcsin}(@t{sin}(x))} changes
- to @cite{x}. Also, @cite{@t{arcsin}(@t{cos}(x))} and
- @cite{@t{arccos}(@t{sin}(x))} both change to @cite{@t{pi}/2 - x}.
- These simplifications are unsafe because they are valid only for
- values of @cite{x} in a certain range; outside that range, values
- are folded down to the 360-degree range that the inverse trigonometric
- functions always produce.
- X
- Powers of powers @cite{(x^a)^b} are simplified to @c{$x^{a b}$}
- @cite{x^(a b)}
- for all @cite{a} and @cite{b}. These results will be valid only
- in a restricted range of @cite{x}; for example, in @c{$(x^2)^{1:2}$}
- @cite{(x^2)^1:2}
- the powers cancel to get @cite{x}, which is valid for positive values
- of @cite{x} but not for negative or complex values.
- X
- Similarly, @cite{@t{sqrt}(x^a)} and @cite{@t{sqrt}(x)^a} are both
- simplified (possibly unsafely) to @c{$x^{a/2}$}
- @cite{x^(a/2)}.
- X
- Forms like @cite{@t{sqrt}(1 - @t{sin}(x)^2)} are simplified to, e.g.,
- @cite{@t{cos}(x)}. Calc has identities of this sort for @code{sin},
- @code{cos}, @code{tan}, @code{sinh}, and @code{cosh}.
- X
- Arguments of square roots are partially factored to look for
- squared terms that can be extracted. For example,
- @cite{@t{sqrt}(a^2 b^3 + a^3 b^2)} simplifies to @cite{a b @t{sqrt}(a+b)}.
- X
- The simplifications of @cite{@t{ln}(@t{exp}(x))}, @cite{@t{ln}(@t{e}^x)},
- and @cite{@t{log10}(10^x)} to @cite{x} are unsafe for similar
- reasons.
- X
- Common factors are cancelled from products on both sides of an
- equation, even if those factors may be zero: @cite{a x / b x}
- to @cite{a / b}. Such factors are never cancelled from
- inequalities: Even @kbd{a e} is not bold enough to reduce
- @cite{a x < b x} to @cite{a < b} (or @cite{a > b}, depending
- on whether you believe @cite{x} is positive or negative).
- X
- @node Simplification of Units, , Unsafe Simplifications, Simplifying Formulas
- @subsection Simplification of Units
- X
- @noindent
- The simplifications described in this section are applied by the
- @kbd{u s} (@code{calc-simplify-units}) command. These are in addition
- to the regular @kbd{a s} (but not @kbd{a e}) simplifications described
- earlier. @xref{Basic Operations on Units}.
- X
- The variable @code{UnitSimpRules} contains rewrites to be applied by
- the @kbd{u s} command. These are applied in addition to @code{EvalRules}
- and @code{AlgSimpRules}.
- X
- Scalar mode is automatically put into effect when simplifying units.
- @xref{Matrix Mode}.
- X
- Sums @cite{a + b} involving units are simplified by extracting the
- units from @cite{a} as if by the @kbd{u x} command (call the result
- @cite{u_a}), then simplifying the expression @cite{b / u_a}
- using @kbd{u b} and @kbd{u s}. If the result has units then the sum
- is inconsistent and is left alone. Otherwise, it is rewritten
- in terms of the units @cite{u_a}.
- X
- If units auto-ranging mode is enabled, products or quotients in
- which the first argument is a number which is out of range for the
- leading unit are modified accordingly.
- X
- When cancelling and combining units in products and quotients,
- Calc accounts for unit names that differ only in the prefix letter.
- For example, @samp{2 km m} is simplified to @samp{2000 m^2}.
- However, compatible but different units like @code{ft} and @code{in}
- are not combined in this way.
- X
- Quotients @cite{a / b} are simplified in two additional ways. First,
- if @cite{b} is a number or a product beginning with a number, Calc
- computes the reciprocal of this number and moves it to the numerator.
- X
- For each pair of unit names from the numerator and denominator
- of a quotient, if the units are compatible (e.g., they are both
- units of area) then they are replaced by the ratio between those
- units. For example, in @samp{3 s in N / kg cm} the units
- @samp{in / cm} will be replaced by @cite{2.54}.
- X
- For powers and square roots, the ``unsafe'' simplifications
- @cite{(a b)^c} to @cite{a^c b^c}, @cite{(a/b)^c} to @cite{a^c / b^c},
- and @cite{(a^b)^c} to @c{$a^{b c}$}
- @cite{a^(b c)} are done if the powers are
- real numbers. (These are safe in the context of units because
- all numbers involved can reasonably be assumed to be real.)
- X
- Also, if a unit name is raised to a fractional power, and the
- base units in that unit name all occur to powers which are a
- multiple of the denominator of the power, then the unit name
- is expanded out into its base units, which can then be simplified
- according to the previous paragraph. For example, @samp{acre^1.5}
- is simplified by noting that @cite{1.5 = 3:2}, that @samp{acre}
- is defined in terms of @samp{m^2}, and that the 2 in the power of
- @code{m} is a multiple of 2 in @cite{3:2}. Thus, @code{acre^1.5} is
- replaced by approximately @c{$(4046 m^2)^{1.5}$}
- @cite{(4046 m^2)^1.5}, which is then
- changed to @c{$4046^{1.5} \, (m^2)^{1.5}$}
- @cite{4046^1.5 (m^2)^1.5}, then to @cite{257440 m^3}.
- X
- The functions @code{float}, @code{frac}, @code{clean}, @code{abs},
- as well as @code{floor} and the other integer truncation functions,
- applied to unit names or products or quotients involving units are
- simplified. For example, @samp{round(1.6 in)} is changed to
- @samp{round(1.6) round(in)}; the lefthand term evaluates to 2,
- and the righthand term simplifies to @code{in}.
- X
- The functions @code{sin}, @code{cos}, and @code{tan} with arguments
- that have angular units like @code{rad} or @code{arcmin} are
- simplified by converting to base units (radians), then evaluating
- with the angular mode temporarily set to radians.
- X
- @node Polynomials, Calculus, Simplifying Formulas, Algebra
- @section Polynomials
- X
- A @dfn{polynomial} is a sum of terms which are coefficients times
- various powers of a ``base'' variable. For example, @cite{2 x^2 + 3 x - 4}
- is a polynomial in @cite{x}. Some formulas can be considered
- polynomials in several different variables: @cite{1 + 2 x + 3 y + 4 x y^2}
- is a polynomial in both @cite{x} and @cite{y}. Polynomial coefficients
- are often numbers, but they may in general be any formulas not
- involving the base variable.
- X
- @kindex a f
- @pindex calc-factor
- @tindex factor
- The @kbd{a f} (@code{calc-factor}) [@code{factor}] command factors a
- polynomial into a product of terms. For example, the polynomial
- @samp{x^3 + 2 x^2 + x} is factored into @samp{x*(x+1)^2}. As another
- example, @samp{a c + b d + b c + a d} is factored into the product
- @samp{(a + b) (c + d)}.
- X
- Calc currently has three algorithms for factoring. Formulas which are
- linear in several variables, such as the second example above, are
- merged according to the distributive law. Formulas which are
- polynomials in a single variable, with constant integer or fractional
- coefficients, are factored into irreducible linear and/or quadratic
- terms. The first example above factors into three linear terms
- (@samp{x}, @samp{x+1}, and @samp{x+1} again). Finally, formulas
- which do not fit the above criteria are handled by the algebraic
- rewrite mechanism.
- X
- Calc's polynomial factorization algorithm works by using the general
- root-finding command (@kbd{a P}) to solve for the roots of the
- polynomial. It then looks for roots which are rational numbers
- or complex-conjugate pairs, and converts these into linear and
- quadratic terms, respectively. Because it uses floating-point
- arithmetic, it may be unable to find terms that involve large
- integers (whose number of digits approaches the current precision).
- Also, irreducible factors of degree higher than quadratic are not
- found, and polynomials in more than one variable are not treated.
- (A more robust factorization algorithm may be included in a future
- version of Calc.)
- X
- @vindex FactorRules
- @tindex thecoefs
- @tindex thefactors
- The rewrite-based factorization method uses rules stored in the variable
- @code{FactorRules}. @xref{Rewrite Rules}, for a discussion of the
- operation of rewrite rules. The default @code{FactorRules} are able
- to factor quadratic forms symbolically into two linear terms,
- @samp{(a x + b) (c x + d)}. You can edit these rules to include other
- cases if you wish. To use the rules, Calc builds the formula
- @samp{thecoefs(x, [a, b, c, ...])} where @code{x} is the polynomial
- base variable and @code{a}, @code{b}, etc., are polynomial coefficients
- (which may be numbers or formulas). The constant term is written first,
- i.e., in the @code{a} position. When the rules complete, they should have
- changed the formula into the form @samp{thefactors(x, [f1, f2, f3, ...])}
- where each @code{fi} should be a factored term, e.g., @samp{x - ai}.
- Calc then multiplies these terms together to get the complete
- factored form of the polynomial. If the rules do not change the
- @code{thecoefs} call to a @code{thefactors} call, @kbd{a f} leaves the
- polynomial alone on the assumption that it is unfactorable. (Note that
- SHAR_EOF
- true || echo 'restore of calc.texinfo failed'
- fi
- echo 'End of part 45'
- echo 'File calc.texinfo is continued in part 46'
- echo 46 > _shar_seq_.tmp
- exit 0
- exit 0 # Just in case...
- --
- Kent Landfield INTERNET: kent@sparky.IMD.Sterling.COM
- Sterling Software, IMD UUCP: uunet!sparky!kent
- Phone: (402) 291-8300 FAX: (402) 291-4362
- Please send comp.sources.misc-related mail to kent@uunet.uu.net.
-